package com.lmds.sprindemo1.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.*;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

@Aspect
@Component
public class DemoAspect {


    //Introductions 引入
    @DeclareParents(value = "com.lmds.sprindemo1.aop.*+", defaultImpl = DemoInterfaceImpl.class)
    public static DemoInterface demoInterface;

    @Pointcut("execution(* com.lmds.sprindemo1.aop.*.*(..))")
    public void demoPointCut() {
    }

    @Pointcut("within(DemoAopExecuteClass)")
    public void demoPointCutThis() {
    }


    @Before("demoPointCut()")
    public void before(JoinPoint joinPoint) {
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        Method method = signature.getMethod();
        System.out.println("demoPointCut @Before," + method);

    }

    @After("demoPointCut()")
    public void after(JoinPoint joinPoint) {
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        Method method = signature.getMethod();
        System.out.println("demoPointCut @After," + method);

    }

    @After("execution(* test())")
    public void afterTest(JoinPoint joinPoint) {
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        Method method = signature.getMethod();
        System.out.println("afterTest @After," + method);

    }


}

